package com.kingyea.mobilepolice.apimanage.servicehistory.controller;

import com.kingyea.mobilepolice.apimanage.log.OperateType;
import com.kingyea.mobilepolice.apimanage.log.OperationLogAnnotation;
import com.kingyea.mobilepolice.apimanage.servicehistory.bean.ServiceHistory;
import com.kingyea.mobilepolice.apimanage.servicehistory.service.ServiceHistoryService;
import com.kingyea.mobilepolice.apimanage.serviceinfo.bean.ServiceInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ServiceHistory 控制层
 * @date Created in 2018-05-05 17:51:23
 */
@RequestMapping(value = "/serviceHistory")
@RestController
public class ServiceHistoryController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceHistoryController.class);

    @Autowired
    private ServiceHistoryService serviceHistoryService;

    /**
     * 根据搜索条件搜索历史接口列表
     *
     * @param map
     * @return com.device.mall.utils.page.PageInfo
     * @author Mr.Lin
     * @date 2017/11/20 15:57
     */
    @ApiOperation(value = "根据搜索条件搜索历史接口列表", notes = "", response = ServiceInfo.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "serviceSerialNo", value = " 接口唯一标识 ", required = false, dataType = "Integer")
            , @ApiImplicitParam(name = "pageNum", value = "第几页", required = true, dataType = "int")
            , @ApiImplicitParam(name = "pageSize", value = "每页数据数量大小", required = true, dataType = "int")
    })
    @OperationLogAnnotation(operateName = "根据搜索条件搜索接口列表", operateType = OperateType.SELECT, module = "serviceinfo")
    @RequestMapping(value = "/searchByCondition", method = RequestMethod.POST)
    public Object searchByCondition(@RequestBody Map<String, Object> map) throws Exception {
        return serviceHistoryService.searchByCondition(map);
    }


    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public Object list() throws Exception {
        return serviceHistoryService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param serviceSerialNo
     * @param version
     * @return
     */
    @RequestMapping(value = "/{serviceSerialNo}/{version}", method = RequestMethod.GET)
    public Object detail(@PathVariable String serviceSerialNo, @PathVariable String version) throws Exception {
        return serviceHistoryService.getById(serviceSerialNo, version);
    }

    /**
     * 创建
     *
     * @param serviceHistory
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody ServiceHistory serviceHistory) throws Exception {
        return serviceHistoryService.save(serviceHistory);
    }

    /**
     * 更新
     *
     * @param serviceHistory
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public Object update(@RequestBody ServiceHistory serviceHistory) throws Exception {
        return serviceHistoryService.update(serviceHistory);
    }

    /**
     * 删除
     *
     * @param serviceSerialNo
     * @param version
     * @return
     */
    @RequestMapping(value = "/{serviceSerialNo}/{version}", method = RequestMethod.DELETE)
    public Object delete(@PathVariable String serviceSerialNo, @PathVariable String version) throws Exception {
        return serviceHistoryService.deleteById(serviceSerialNo, version);
    }

}
